﻿using System;

namespace GameFramework.Utility
{
    /// <summary>
    /// 借助IDisposable实现的引用计数器 调用AddRef令计数+1 在Dispose时计数-1
    /// </summary>
    public sealed class DisposableRefCounter : IDisposable
    {
        public int RefCount { get; private set; }
        
        public bool AnyRef => RefCount > 0;

        public IDisposable AddRef()
        {
            ++RefCount;
            return this;
        }

        public void Dispose()
        {
            --RefCount;
        }
    }
}